#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
@author: Lénia Andrade nº 5607
'''


class CreateHTML:
   
    '''
    This method creates an html file referent to the first statistic (establishments per year) 
    '''
    def html_establishments_year(self, year, establishments):

    
        file = open('html/Establishments_Year.html', 'wb')

        html_content = '''<head>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        </head>
                        <body>
                        <h1 align="center">Establishments per year</h1>
                        <br>
                        <br>
                        <br>
                        <table align="center" border="1" id="table" width="30%" summary="This table shows the number of establishments in a certain year">
                        <tr>
                            <th id="year">Year</th>
                            <th id="nr_estab">Number of establishments</th>
                        </tr>
                        
                        <tr>
                            <td headers="year" align="center">{0}</td>
                            <td headers="nr_estab" align="center">{1}</td>
                        </tr>
                        </table>
                        <br>
                        <br>
                        <br>
                        <br><b>The establishments in {0} are:</b><br>
                        </br>'''.format(year, len(establishments))
                        
        file.write(html_content)
    
        for x in establishments:
            file.write(x.encode('utf-8') + '</br>')
            pass
        
        file.write('</body>')
        file.write('</html>')
        file.close()
        pass
    
    
    
    '''
    This method creates an html file referent to the second statistic
    (teachers divided per categories per establishment and per year)
    '''
    def html_teachers_cat_estab_year(self, year, estab, cat, teachers):
    
        file = open('html/Teachers_Category_Establishment_Year.html', 'wb')

        html_content = '''<head>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        </head>
                        <body>
                        <h1 align="center">Teachers divided per categories per establishments and per year</h1>
                        <br>
                        <br>
                        <br>
                        <table align="center" border="1" id="table" width="40%" summary="This table shows the number of teacher divided per categories per establishments in a certain year">
                        <tr>
                            <th id="year">Year</th>
                            <th id="estab">Establishment</th>
                            <th id="cat">Category</th>
                            <th id="nr_teachers">Number of teachers</th>
                        </tr>
                        
                        <tr>
                            <td headers="year" align="center">{0}</td>
                            <td headers="estab" align="center">{1}</td>
                            <td headers="cat" align="center">{2}</td>
                            <td headers="nr_teachers" align="center">{3}</td>
                        </tr>
                        </table>
                        <br>
                        <br>
                        <br>
                        <br><b>The teachers belonging to {1} as {2} in {0} are:</b><br>
                        </br>'''.format(year, estab.encode('utf-8'), cat.encode('utf-8') , len(teachers))
                        
        file.write(html_content)
    
        for x in teachers:
            file.write(x.encode('utf-8') + '</br>')
            pass
        
        file.write('</body>')
        file.write('</html>')
        file.close()
        pass
    
    
    '''
    This method creates an html file referent to third statistic 
    (teachers divided per type of degree per establishment per category and per year)
    '''
    def html_teachers_deg_estab_cat_year(self, year, estab, deg, cat, teachers):
        
        
        file = open('html/Teachers_Degree_Establishment_Category_Year.html', 'wb')

        html_content = '''<head>
                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                        </head>
                        <body>
                        <h1 align="center">Teachers divided per type of degree per establishments per categories and per year</h1>
                        <br>
                        <br>
                        <br>
                        <table align="center" border="1" id="table" width="50%" summary="This table shows the number of teacher divided per categories per establishments in a certain year">
                        <tr>
                            <th id="year">Year</th>
                            <th id="estab">Establishment</th>
                            <th id="deg">Degree</th>
                            <th id="cat">Category</th>
                            <th id="nr_teachers">Number of teachers</th>
                        </tr>
                        
                        <tr>
                            <td headers="year" align="center">{0}</td>
                            <td headers="estab" align="center">{1}</td>
                            <td headers="deg" align="center">{2}</td>
                            <td headers="cat" align="center">{3}</td>
                            <td headers="nr_teachers" align="center">{4}</td>
                        </tr>
                        </table>
                        <br>
                        <br>
                        <br>
                        <br><b>The teachers belonging to {1} as {3} in {0} as {2} are:</b></br>
                        </br>'''.format(year, estab.encode('utf-8'), deg.encode('utf-8'), cat.encode('utf-8') , len(teachers))
                        
        file.write(html_content)
    
        for x in teachers:
            file.write(x.encode('utf-8') + '</br>')
            pass
        
        file.write('</body>')
        file.write('</html>')
        file.close()
        pass
    
    
    '''
    This method creates an html file containing an index
    '''
    def html_index(self):  
            
        file = open('index.html', 'wb')
    
        html_content = '''<head>
                            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                            </head>
                            <body>
                            <h1 align="center">Statistics</h1>
                            <br>
                            <br>
                            <br>
                            <a href="html/Establishments_Year.html" target="blank"><h2 align="center"> Establishments per year </h2></a>
                            <a href="html/Teachers_Category_Establishment_Year.html" target="blank"><h2 align="center">Teachers divided per categories per establishments and per year</h2></a>
                            <a href="html/Teachers_Degree_Establishment_Category_Year.html" target="blank"><h2 align="center">Teachers divided per type of degree per establishments per categories and per year</h2></a>
                            </body>
                            </html>'''
                            
        file.write(html_content)
        file.close()    
        pass      
    pass
        
        
